#include <func.h>
#define N 10000000

typedef struct{
    int num;
    pthread_mutex_t mutex;
}data_t;

void *function(void*p)
{
    int i;
    data_t *q=(data_t*)p;
    for(i=0;i<N;i++)
    {
        pthread_mutex_lock(&q->mutex);
        q->num++;
        pthread_mutex_unlock(&q->mutex);
    }
    return NULL;
}


int main()
{
    data_t *p;
    p->num=0;
    int ret=pthread_mutex_init(&p->mutex,NULL);
    THREAD_ERR_CHECK(ret,"pthread_mutex_init");
    pthread_t pth;
    ret=pthread_create(&pth,NULL,function,(void*)p);
    THREAD_ERR_CHECK(ret,"pthread_create");
    int i;
    for(i=0;i<N;i++)
    {
        pthread_mutex_lock(&p->mutex);
        p->num++;
        pthread_mutex_unlock(&p->mutex);
    }
    ret=pthread_join(pth,NULL);
    THREAD_ERR_CHECK(ret,"pthread_join");
    printf("num=%d\n",p->num);
    ret=pthread_mutex_destroy(&p->mutex);
    THREAD_ERR_CHECK(ret,"pthread_mutex_destroy");
    return 0;
}